package com.xxx.lease.web.admin.controller.apartment;


import com.xxx.lease.common.result.Result;
import com.xxx.lease.web.admin.service.FileUploadService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@Tag(name = "文件管理")
@RequestMapping("/admin/file")
@RestController
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    /*
    *   MultipartFile:由文件上传解析器提供的API
    *   MultipartFile：接受客户端上传的文件
    *       该API中包含了被上传文件的信息
    * */

    @Operation(summary = "上传文件")
    @PostMapping("upload")
    public Result<String> upload(@RequestParam MultipartFile file) {
        //url:minio服务器中文件的地址 将来要保存到MySQL中
        String url = fileUploadService.upload(file);
        return Result.ok(url);
    }

}
